package com.yswy.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This is Description
 *
 * @author linlifu
 * @date 2018/09/18
 */
public class SerializeUtil {

    private static final Logger log = LoggerFactory.getLogger(SerializeUtil.class);

    public static String serialize(Object object) {
        ObjectMapper mapper = new ObjectMapper();
        String str = "";
        try {
            str = mapper.writeValueAsString(object);
        } catch (Exception e) {
            log.error("Serialize error : " + e.getMessage());
        }
        return str;
    }

    public static Object deSerialize(String str, Object o) {
        ObjectMapper mapper = new ObjectMapper();
        Object object = null;
        try {
            object = mapper.readValue(str, o.getClass());
        } catch (Exception e) {
            log.error("deSerialize error : " + e.getMessage());
        }
        return object;
    }


}
